package com.dzu.easy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhaoDong
 * @date 2023/2/6 13:28
 * @description 205. 同构字符串
 */
public class Test205 {

    public static void main(String[] args) {
        System.out.println(isIsomorphic("badc", "baba"));
        System.out.println(isIsomorphic("egg", "add"));
    }

    public static boolean isIsomorphic(String s, String t) {

        if (s.length() != t.length()) {
            return false;
        }
        Map<Character, Character> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char s1 = s.charAt(i);
            char t1 = t.charAt(i);

            if (map.containsKey(s1)) {
                if (map.get(s1) != t1) {
                    return false;
                }
            } else {
                if (map.containsValue(t1)) {
                    return false;
                }
                map.put(s1, t1);
            }

        }
        return true;


    }
}
